﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace TaxService
{
    /// <summary>
    /// TaxService 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消对下行的注释。
    // [System.Web.Script.Services.ScriptService]
    public class TaxService : System.Web.Services.WebService
    {
        /// <summary>
        /// 请求开票
        /// 1、正常发票
        /// 2、红字发票
        /// </summary>
        /// <param name="ParameterXml"></param>
        /// <?xml version=”1.0” encoding=”GB2312”?> 
        /// <ROOT> 
        ///     <TAX_INVOICE_NUM></TAX_INVOICE_NUM> 
        ///     <INCOME_INVOICE_DATE_START></INCOME_INVOICE_DATE_START> 
        ///     <INCOME_INVOICE_DATE_END></INCOME_INVOICE_DATE_END> 
        ///     <INVOICE_TITLE></INVOICE_TITLE> 
        ///     < STATION_NUM ></ STATION_NUM > 
        ///     < MACHINE_NUM ></ MACHINE_NUM > 
        ///     <ORDER_NUM></ ORDER_NUM > 
        /// </ROOT> 
        /// <returns></returns>
        [WebMethod]
        public string GetInvoiceInfo(string ParameterXml)
        {
            Guid guid = Guid.NewGuid();
            try
            {

                Log.Logger.Writer("invoice" + guid.ToString(), Log.QueueStatus.Open, "访问接口：GetInvoicesInfo");
                Log.Logger.Writer("invoice" + guid.ToString(), Log.QueueStatus.Open, "访问参数：" + ParameterXml);
                Invoices invoice = new Invoices();
                string XmlString = invoice.InvoicesXML();
                Log.Logger.Writer("invoice" + guid.ToString(), Log.QueueStatus.Open, XmlString);
                Log.Logger.Writer("invoice" + guid.ToString(), Log.QueueStatus.Close, "接口访问结束");
                return XmlString;
            }
            catch (Exception ex)
            {
                Log.Logger.Writer("invoice" + guid.ToString(), Log.QueueStatus.Close, ex);
                return ex.ToString();
            }
        }
        /// <summary>
        /// 反馈发票信息
        /// 1、正常的发票
        /// 2、作废的发票
        /// 3、红字发票
        /// </summary>
        /// <param name="ParameterXml"></param>
        /// <?xml version="1.0" encoding="GB2312"?> 
        /// <ROOT> 
        ///     <T_FPHDR_OUT> 
        ///         <INCOME_INVOICE_NUM></INCOME_INVOICE_NUM> 
        ///         <TAX_INVOICE_NUM></TAX_INVOICE_NUM> 
        ///         <TOTAL_MONEY></TOTAL_MONEY> 
        ///         <INVOICE_STATU></ INVOICE_STATU> 
        ///     </T_FPHDR_OUT> 
        ///     <T_FPITEM_OUT><!-- 子节点 -->  
        ///         <INCOME_INVOICE_NUM></INCOME_INVOICE_NUM>
        ///         <INCOME_INVOICE_LINE_ID></INCOME_INVOICE_LINE_ID> 
        ///         <TAXES></TAXES> 
        ///         <NO_TAX_AMOUNT></NO_TAX_AMOUNT> 
        ///         <TOTAL_TAX_PRICE></TOTAL_TAX_PRICE> 
        ///     </T_FPITEM_OUT>         
        /// </ROOT>
        /// <returns></returns>
        [WebMethod]
        public string ReturnInvoiceInfo(string ParameterXml)
        {
            Guid guid = Guid.NewGuid();
            try
            {
                Log.Logger.Writer("ReturnInvoiceInfo" + guid.ToString(), Log.QueueStatus.Open, "访问接口：ReturnInvoiceInfo");
                Log.Logger.Writer("ReturnInvoiceInfo" + guid.ToString(), Log.QueueStatus.Open, "访问参数：" + ParameterXml);
                Invoices invoice = new Invoices();
                var result = invoice.ReturnInvoice(ParameterXml);
                Log.Logger.Writer("ReturnInvoiceInfo" + guid.ToString(), Log.QueueStatus.Open, "返回结果：" + result);
                Log.Logger.Writer("ReturnInvoiceInfo" + guid.ToString(), Log.QueueStatus.Close, "接口访问结束");
                return result;
            }
            catch (Exception ex)
            {
                Log.Logger.Writer("ReturnInvoiceInfo" + guid.ToString(), Log.QueueStatus.Close, ex);
                return ex.ToString();
            }
        }
        /// <summary>
        /// 删除发票
        /// </summary>
        /// <?xml version="1.0" encoding="GB2312"?> 
        /// <ROOT> 
        ///     <Item>
        ///     <INCOME_INVOICE_NUM></INCOME_INVOICE_NUM>
        ///     <ORDER_STATU></ORDER_STATU ><!--0-正常，1-单据错误 -->
        ///     </Item>        
        /// </ROOT> 
        /// <param name="ParameterXml"></param>
        /// <returns></returns>
        [WebMethod]
        public string DeleteInvoiceInfo(string ParameterXml)
        {
            Guid guid = Guid.NewGuid();
            try
            {
                Log.Logger.Writer("DeleteInvoiceInfo" + guid.ToString(), Log.QueueStatus.Open, "访问接口：DeleteInvoiceInfo");
                Log.Logger.Writer("DeleteInvoiceInfo" + guid.ToString(), Log.QueueStatus.Open, "访问参数：" + ParameterXml);
                Invoices invoice = new Invoices();
                var result = invoice.DeleteInvoice(ParameterXml);
                Log.Logger.Writer("DeleteInvoiceInfo" + guid.ToString(), Log.QueueStatus.Open, "返回结果：" + result);
                Log.Logger.Writer("DeleteInvoiceInfo" + guid.ToString(), Log.QueueStatus.Close, "接口访问结束");
                return result;
            }
            catch (Exception ex)
            {
                Log.Logger.Writer("DeleteInvoiceInfo" + guid.ToString(), Log.QueueStatus.Close, ex);
                return ex.ToString();
            }
        }
    }
}
